// 测试"一键报名"按钮禁用功能的完整测试

// 模拟岗位数据 - 包含各种状态
const mockJobData = [
	{
		id: '1',
		title: '普工',
		salary: '18元/小时',
		location: '深圳某工厂',
		signup: false, // 未报名
		distance: 2.5,
		tags: ['五险一金', '包吃住'],
		engagement: '已有23人关注'
	},
	{
		id: '2',
		title: '技术员',
		salary: '25元/小时',
		location: '东莞某工厂',
		signup: true, // 已报名
		distance: 5.2,
		tags: ['双休', '年终奖'],
		engagement: '已有45人关注'
	},
	{
		id: '3',
		title: '质检员',
		salary: '20元/小时',
		location: '惠州某工厂',
		signup: null, // 未定义
		distance: 1.8,
		tags: ['五险一金'],
		engagement: '已有12人关注'
	}
]

// 测试JobCard组件的按钮状态
function testJobCardButtonState() {
	console.log('=== 测试JobCard组件的按钮状态 ===')
	
	mockJobData.forEach((job, index) => {
		const buttonText = job.signup ? '已报名' : '一键报名'
		const isDisabled = job.signup === true
		const canClick = !isDisabled
		const buttonClasses = ['apply-btn', ...(isDisabled ? ['disabled'] : [])]
		
		console.log(`岗位${index + 1}: ${job.title}`)
		console.log(`  signup字段: ${job.signup}`)
		console.log(`  按钮文字: ${buttonText}`)
		console.log(`  是否禁用: ${isDisabled}`)
		console.log(`  是否可点击: ${canClick}`)
		console.log(`  样式类名: ${buttonClasses.join(' ')}`)
		console.log('---')
	})
}

// 测试jobs.vue页面的按钮状态
function testJobsPageButtonState() {
	console.log('=== 测试jobs.vue页面的按钮状态 ===')
	
	mockJobData.forEach((job, index) => {
		const buttonText = job.signup ? '已报名' : '一键报名'
		const isDisabled = job.signup === true
		const canClick = !isDisabled
		const buttonClasses = ['apply-btn', ...(isDisabled ? ['disabled'] : [])]
		
		console.log(`岗位${index + 1}: ${job.title}`)
		console.log(`  signup字段: ${job.signup}`)
		console.log(`  按钮文字: ${buttonText}`)
		console.log(`  是否禁用: ${isDisabled}`)
		console.log(`  是否可点击: ${canClick}`)
		console.log(`  样式类名: ${buttonClasses.join(' ')}`)
		console.log('---')
	})
}

// 测试搜索页面的按钮状态
function testSearchPageButtonState() {
	console.log('=== 测试搜索页面的按钮状态 ===')
	
	mockJobData.forEach((job, index) => {
		const buttonText = job.signup ? '已报名' : '一键报名'
		const isDisabled = job.signup === true
		const canClick = !isDisabled
		
		console.log(`岗位${index + 1}: ${job.title}`)
		console.log(`  signup字段: ${job.signup}`)
		console.log(`  按钮文字: ${buttonText}`)
		console.log(`  是否禁用: ${isDisabled}`)
		console.log(`  是否可点击: ${canClick}`)
		console.log('---')
	})
}

// 测试数据转换逻辑
function testDataTransformation() {
	console.log('=== 测试数据转换逻辑 ===')
	
	const mockApiResponse = [
		{
			hireRecruitUseId: '1',
			hireName: '普工',
			workPrice: '18',
			customerName: '深圳某工厂',
			address: '深圳市南山区',
			isSignup: false,
			distance: '2.5'
		},
		{
			hireRecruitUseId: '2',
			hireName: '技术员',
			workPrice: '25',
			customerName: '东莞某工厂',
			address: '东莞市长安镇',
			isSignup: true,
			distance: '5.2'
		}
	]
	
	console.log('API返回的原始数据:')
	console.log(JSON.stringify(mockApiResponse, null, 2))
	
	const transformedData = mockApiResponse.map((job: any) => ({
		id: job.hireRecruitUseId,
		title: job.hireName || '招聘岗位',
		salary: job.workPrice ? `${job.workPrice}元/小时` : '面议',
		location: job.customerName,
		signup: job.isSignup, // 关键字段转换
		distance: job.distance
	}))
	
	console.log('\n转换后的数据:')
	console.log(JSON.stringify(transformedData, null, 2))
	
	console.log('\n验证signup字段转换:')
	transformedData.forEach((job, index) => {
		console.log(`岗位${index + 1}: ${job.title} - signup: ${job.signup}`)
	})
}

// 测试按钮点击事件处理
function testButtonClickHandling() {
	console.log('=== 测试按钮点击事件处理 ===')
	
	mockJobData.forEach((job, index) => {
		if (job.signup === true) {
			console.log(`岗位${index + 1}: ${job.title} - 已报名，点击事件被阻止`)
		} else {
			console.log(`岗位${index + 1}: ${job.title} - 未报名，点击事件正常触发`)
		}
	})
}

// 测试样式渲染
function testStyleRendering() {
	console.log('=== 测试样式渲染 ===')
	
	mockJobData.forEach((job, index) => {
		const baseStyle = 'background-color: var(--u-primary); border-radius: 20rpx; padding: 12rpx 24rpx;'
		const disabledStyle = 'background-color: #CCCCCC; cursor: not-allowed; opacity: 0.6;'
		
		if (job.signup === true) {
			console.log(`岗位${index + 1}: ${job.title}`)
			console.log(`  基础样式: ${baseStyle}`)
			console.log(`  禁用样式: ${disabledStyle}`)
		} else {
			console.log(`岗位${index + 1}: ${job.title}`)
			console.log(`  基础样式: ${baseStyle}`)
			console.log(`  禁用样式: 无`)
		}
		console.log('---')
	})
}

// 模拟组件渲染
function simulateComponentRender() {
	console.log('=== 模拟组件渲染 ===')
	
	mockJobData.forEach((job, index) => {
		// JobCard组件的按钮渲染
		const jobCardButton = `
			<view 
				class="apply-btn ${job.signup ? 'disabled' : ''}"
				@click.stop="${job.signup ? 'null' : 'handleApplyClick'}"
			>
				<text class="apply-text">${job.signup ? '已报名' : '一键报名'}</text>
			</view>
		`
		
		// jobs.vue页面的按钮渲染
		const jobsPageButton = `
			<view 
				class="apply-btn ${job.signup ? 'disabled' : ''}"
				@click.stop="${job.signup ? 'null' : 'applyJob(job, index)'}"
			>
				<text class="apply-text">${job.signup ? '已报名' : '一键报名'}</text>
			</view>
		`
		
		console.log(`岗位${index + 1}: ${job.title}`)
		console.log(`  JobCard按钮: ${jobCardButton.trim()}`)
		console.log(`  jobs.vue按钮: ${jobsPageButton.trim()}`)
		console.log('---')
	})
}

// 运行所有测试
function runAllTests() {
	testJobCardButtonState()
	testJobsPageButtonState()
	testSearchPageButtonState()
	testDataTransformation()
	testButtonClickHandling()
	testStyleRendering()
	simulateComponentRender()
}

// 导出测试函数
export {
	testJobCardButtonState,
	testJobsPageButtonState,
	testSearchPageButtonState,
	testDataTransformation,
	testButtonClickHandling,
	testStyleRendering,
	simulateComponentRender,
	runAllTests,
	mockJobData
}

// 如果直接运行此文件，执行所有测试
if (typeof window === 'undefined') {
	runAllTests()
}
